package com.example.service_sms.controller;

import com.example.common.commonsutils.R;
import com.example.service_sms.service.SMSService;
import com.example.service_sms.utils.SMSConst;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:tjf
 * @Description:
 */
@Tag(name = "短信服务控制器")
@RestController
@RequestMapping("/smsservice")
public class SMSController {
    @Resource
    private SMSService smsService;
    @Operation(description = "发送登录短信")
    @GetMapping("/login/{phone}")
    public R sendLoginMessage(@PathVariable String phone){
        int flag = smsService.sendLoginMessage(phone);
        if (flag == SMSConst.SMS_SUCCESS){
            return R.ok();
        }else if (flag == SMSConst.SMS_NOT_EXPIRE){
            return R.error().message("存在未过期短信");
        }else {
            return R.error().message("短信发送失败");
        }
    }

    @Operation(description = "发送注册短信")
    @GetMapping("/register/{phone}")
    public R sendRegisterMessage(@PathVariable String phone){
        int flag = smsService.sendRegisterMessage(phone);
        if (flag == SMSConst.SMS_SUCCESS){
            return R.ok();
        }else if (flag == SMSConst.SMS_NOT_EXPIRE){
            return R.error().message("存在未过期短信");
        }else {
            return R.error().message("短信发送失败");
        }
    }
}
